package logic

import (
	"context"
	"home-view/api/internal/svc"
	"home-view/api/internal/types"
	"home-view/homerpc/homerpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ResetPasswordApiLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewResetPasswordApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResetPasswordApiLogic {
	return &ResetPasswordApiLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ResetPasswordApiLogic) ResetPasswordApi(req *types.ResetPasswordRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	password, err := l.svcCtx.HomeRpc.ResetPassword(l.ctx, &homerpc.ResetPasswordRequest{
		Phone:       req.Phone,
		Password:    req.Password,
		SendSmsCode: req.SendSmsCode,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "登录成功",
		Code:    200,
		Data:    password,
	}, nil
}
